using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class GetAllExp : GameplayObject
	{
		void OnTriggerEnter2D(Collider2D other)
		{

			if (other.GetComponent<CollectableArea>())
			{
				AudioKit.PlaySound("die");
				foreach (var exp in FindObjectsByType<Exp>(FindObjectsInactive.Exclude, FindObjectsSortMode.None))
				{
					ActionKit.OnUpdate.Register(() =>//注册帧更新/UI调试回调；
					{
						var player = Player.Default;
						if (player)
						{
							var direction = player.Position() - exp.Position();
							exp.transform.Translate(direction.normalized * Time.deltaTime * 5f);
						}
					}).UnRegisterWhenGameObjectDestroyed(exp);//取消注册 “当 GameObject（游戏对象）销毁时”
				}
				this.DestroyGameObjGracefully();
			}

		}
		public override Collider2D collision2D => SelfCircleCollider2D;
	}
}
